package com.reactim.user.entity;

import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.time.LocalDateTime;

/**
 * 用户好友关系实体类
 */
@Data
@Entity
@Table(name = "user_friends", 
       uniqueConstraints = @UniqueConstraint(columnNames = {"userId", "friendId"}))
@EntityListeners(AuditingEntityListener.class)
@EqualsAndHashCode(callSuper = false)
public class UserFriend {
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    
    @Column(nullable = false)
    private Long userId;
    
    @Column(nullable = false)
    private Long friendId;
    
    @Column(length = 50)
    private String remark; // 好友备注
    
    @Column
    private Long groupId; // 所属分组ID
    
    @Enumerated(EnumType.ORDINAL)
    @Column(nullable = false)
    private FriendStatus status = FriendStatus.NORMAL;
    
    @CreatedDate
    @Column(nullable = false, updatable = false)
    private LocalDateTime createdAt;
    
    /**
     * 好友状态枚举
     */
    public enum FriendStatus {
        NORMAL(1, "正常"),
        BLOCKED(2, "已拉黑"),
        DELETED(0, "已删除");
        
        private final int code;
        private final String description;
        
        FriendStatus(int code, String description) {
            this.code = code;
            this.description = description;
        }
        
        public int getCode() {
            return code;
        }
        
        public String getDescription() {
            return description;
        }
    }
}